package com.ztrue.framework.infrastructure;

import com.ztrue.framework.infrastructure.impl.DistributeMessage;

/**
 * 表示一个有序的消息
 *
 * @author zhangw
 * @date 2016/10/27 14:26
 * @version: 1.0
 */
public abstract class SequenceMessage<ATID extends Object> extends DistributeMessage implements ISequenceMessage {
    /**
     * 聚合根ID
     */
    private ATID aggregateRootId;
    /**
     * 聚合根字符串ID
     */
    private String aggregateRootStringId;
    /**
     * 聚合根类型名称
     */
    private String aggregateRootTypeName;
    /**
     * 序列消息的主版本
     */
    private Long version;

    /**
     * 获取聚合根ID
     *
     * @return
     */
    public ATID getAggregateRootId() {
        return aggregateRootId;
    }

    /**
     * 设置聚合根ID
     *
     * @param aggregateRootId
     */
    public void setAggregateRootId(ATID aggregateRootId) {
        this.aggregateRootId = aggregateRootId;
        this.aggregateRootStringId = aggregateRootId.toString();
    }

    /**
     * 获取聚合根字符串ID
     *
     * @return
     */
    public String getAggregateRootStringId() {
        return aggregateRootStringId;
    }

    /**
     * 设置聚合根字符串ID
     *
     * @param aggregateRootStringId
     */
    public void setAggregateRootStringId(String aggregateRootStringId) {
        this.aggregateRootStringId = aggregateRootStringId;
    }

    /**
     * 获取聚合根类型名称
     *
     * @return
     */
    public String getAggregateRootTypeName() {
        return aggregateRootTypeName;
    }

    /**
     * 设置聚合根类型名称
     *
     * @param aggregateRootTypeName
     */
    public void setAggregateRootTypeName(String aggregateRootTypeName) {
        this.aggregateRootTypeName = aggregateRootTypeName;
    }

    /**
     * 获取序列消息的主版本
     *
     * @return
     */
    public Long getVersion() {
        return version;
    }

    /**
     * 设置序列消息的主版本
     *
     * @param version
     */
    public void setVersion(Long version) {
        this.version = version;
    }

    /**
     * 获取路由密匙
     *
     * @return
     */
    @Override
    public String getRoutingKey() {
        return getAggregateRootStringId();
    }
}
